package com.example.yuejianapp14.Activity.Model;

import com.example.yuejianapp14.Activity.JavaBean.Act;
import com.example.yuejianapp14.Activity.JavaBean.Game;
import com.example.yuejianapp14.Activity.Listener.ActListener;
import com.example.yuejianapp14.Activity.Listener.ClubNoListListener;
import com.example.yuejianapp14.Activity.Listener.GameListener;
import com.example.yuejianapp14.Activity.Servics.ActService;
import com.example.yuejianapp14.Activity.Servics.GameService;

import java.util.List;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;
import retrofit2.Retrofit;
import retrofit2.converter.gson.GsonConverterFactory;

/**
 * Created by 张森 on 2017/10/16.
 */

public class GameModel {
    private Retrofit retrofit;
    private String BASEURL ="http://10.0.2.2/YueJian/index.php/Api/Competition/";
    private String HeadPhotoNameDefault="user_headphoto.png";

    public GameModel(){
        retrofit= new Retrofit.Builder()
                .baseUrl(BASEURL)
                .addConverterFactory(GsonConverterFactory.create())
                .build();
    }




    public void getGameList(final GameListener listener){
        GameService gameServic=retrofit.create(GameService.class);
        Call<List<Game>> call=gameServic.getGame();
        call.enqueue(new Callback<List<Game>>() {
            @Override
            public void onResponse(Call<List<Game>> call, Response<List<Game>> response) {
                if (response.isSuccessful() && response.body() != null) {
                    listener.onResponse(response.body());
                } else
                    listener.onFail("onresponse fail");
            }
            @Override
            public void onFailure(Call<List<Game>> call, Throwable t) {
                listener.onFail(t.toString());
            }
        });


    }

    public void gameinfo (String gameid,final ClubNoListListener listener){
        GameService gameService=retrofit.create(GameService.class);
        Call call = gameService.gameinfo(gameid);
        Callback<Game> callback =new Callback<Game>() {
            @Override
            public void onResponse(Call<Game> call, Response<Game> response) {
                if (response.isSuccessful() && response.body() != null) {
                    listener.onResponse(response.body());
                }else
                    listener.onFail("onresponse fail");

            }

            @Override
            public void onFailure(Call<Game> call, Throwable t) {

            }
        };
        call.enqueue(callback);
    }

}
